package com.ctgu.rabbitmq.rabbitmq.queue.reject;

import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @ ClassName RejectConsumer
 * @ Author Alex2
 * @ Date 2025/8/15 8:48
 **/
@Log4j2
@Component
public class RejectConsumer {

    private static final String TAG = "Alex";

    // 普通队列消费者
    @RabbitListener(queues = RejectConfig.NORMAL_QUEUE_REJECT)
    public void consumeNormal(Message message, Channel channel) throws IOException {
        String body = new String(message.getBody());
        log.debug("{} : 普通队列收到消息 : {}", TAG, body);

        // 消费者拒绝消费且不重新投递
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
    }

    // 死信队列消费者
    @RabbitListener(queues = RejectConfig.DLX_QUEUE_REJECT)
    public void consumeDLX(String message) {
        log.debug("{} : 死信队列收到消息 : {}", TAG, message);
    }
}
